<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Article;
use Illuminate\Http\Request;


class DataController extends Controller
{

    public function index(Request $request)
    {
        $this->__cate_init__($request);
        $keyword = $request->keyword;
        if($request->catid == 31)return '404';
        if($request->catid == 30)return redirect('/data?catid=32');
        if($keyword)
        {
            $pageList = Article::where('post_type', $request->catid)->where('post_title','like', "%{$keyword}%")->orderBy('id', 'desc')->paginate(15);
        }else {
            $pageList = Article::where('post_type', $request->catid)->orderBy('id', 'desc')->paginate(15);
        }
        $pageList->everypage = 15;
        $pageList->appends(['catid'=> $request->catid]);
        $pageList->appends(['keyword'=> $request->keyword]);

        $category = $this->category;
        $view = 'data.index';
        $total = $pageList->total();
        if($category->id == 33)$view = 'data.facebook';
        return view($view, compact('pageList', 'category', 'keyword','total'));
    }

    public function detail(Request $request)
    {
        $info = Article::findOrFail($request->id);
        if($Agent->isMobile())
        {
            return view('index.mobile.detail', compact('info'));
        }
        return view('index.detail', compact('info'));
    }
}
